package com.example.controller;


import com.alibaba.fastjson.JSON;
import com.example.config.QueueBean;
import com.example.entity.DetailsLogs;
import com.example.service.DetailsLogsService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * <p>
 * 操作日志 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-11-11
 */
@RestController
@RequestMapping("/details-logs")
public class DetailsLogsController {

    @Resource
    DetailsLogsService detailsLogsService;

    @Autowired
    RabbitTemplate rabbitTemplate;

    @PostMapping("insertLog/{operateUserId}/{operateUser}/{operateModules}")
    public void insertLog(@PathVariable Integer operateUserId,
                          @PathVariable String operateUser,
                          @PathVariable String operateModules){
        DetailsLogs detailsLogs = new DetailsLogs();
        detailsLogs.setOperateModules(operateModules);
        detailsLogs.setOperateUserId(operateUserId);
        detailsLogs.setOperateUser(operateUser);
        String entity = JSON.toJSONString(detailsLogs);
        rabbitTemplate.convertAndSend(QueueBean.INSERT_QUEUE_NAME,entity);
//        detailsLogsService.insertLog(detailsLogs);
    }

    @PostMapping("updateLog/{operateUserId}/{operateUser}/{operateModules}")
    public void updateLog(@PathVariable Integer operateUserId,
                          @PathVariable String operateUser,
                          @PathVariable String operateModules){
        DetailsLogs detailsLogs = new DetailsLogs();
        detailsLogs.setOperateModules(operateModules);
        detailsLogs.setOperateUserId(operateUserId);
        detailsLogs.setOperateUser(operateUser);
        detailsLogsService.updateLog(detailsLogs);
    }

    @PostMapping("deleteLog/{operateUserId}/{operateUser}/{operateModules}")
    public void deleteLog(@PathVariable Integer operateUserId,
                          @PathVariable String operateUser,
                          @PathVariable String operateModules){
        DetailsLogs detailsLogs = new DetailsLogs();
        detailsLogs.setOperateModules(operateModules);
        detailsLogs.setOperateUserId(operateUserId);
        detailsLogs.setOperateUser(operateUser);
        detailsLogsService.deleteLog(detailsLogs);
    }



}

